import { Subject } from "rxjs";

// 构造一个主题
const subject = new Subject<number>();

// 订阅者A
const observerA = subject.subscribe({
  next: (v) => console.log(`observerA: ${v}`),
});
// 订阅者B
const observerB = subject.subscribe({
  next: (v) => console.log(`observerB: ${v}`),
});

// 消费
subject.next(1);
subject.next(2);

// Logs:
// observerA: 1
// observerB: 1
// observerA: 2
// observerB: 2
